﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Streamsol.Crm.XrmDevelopmentToolkit
{
    [global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
    public sealed class XrmEntityAttribute : Attribute
    {

        // See the attribute guidelines at
        //  http://go.microsoft.com/fwlink/?LinkId=85236
        readonly string entityName;
        readonly string primaryKeyFieldName;

        public XrmEntityAttribute(string entityName)
            : this(entityName, "Id")
        { }

        public XrmEntityAttribute(string entityName, string primaryKeyFieldName)
        {
            this.entityName = entityName;
            this.primaryKeyFieldName = primaryKeyFieldName;
        }

        public string EntityName
        {
            get { return entityName; }
        }

        public string PrimaryKeyFieldName
        {
            get { return primaryKeyFieldName; }
        }

        /// <summary>
        /// The name of a method that will be called before this entity is being saved. The signature should be: void (DynamicEntity de).
        /// </summary>
        public string OnSaving
        {
            get;
            set;
        }

        /// <summary>
        /// The name of a method that will be called after this entity has been saved. The signature should be: void (Guid entityId).
        /// </summary>
        public string OnSaved
        {
            get;
            set;
        }
    }
}
